<?php

namespace App\Console\Commands;

use App\Jobs\RandStarJob;
use App\Models\Article;
use App\Models\Circle;
use App\Models\CircleCategoryRelate;
use App\Models\Comment;
use App\Models\Star;
use App\Models\User;
use App\Mongo\ArticleMon;
use App\Mongo\CircleMon;
use Illuminate\Console\Command;
use YangJiSen\CacheUserProvider\CacheForget;

class VirtualStarCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'virtual-star';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $total = Article::where('activity_id', 3106)->count();
        $limit = $total - 5;
        $list = Article::where('activity_id', 3106)->orderBy('activity_star_num', 'asc')->limit($limit)->get();
        $arr_user_id = ['378', '412', '408', '398', '393', '394', '395', '430'];
        foreach ($arr_user_id as $uid) {
            if (env('APP_ENV') == 'production') {
                $rand_minute = rand(5, 60);
            } else {
                $rand_minute = rand(1, 5);
            }
            foreach ($list as $item) {
                RandStarJob::dispatch($item->id, $uid)->delay(now()->addMinutes($rand_minute));
            }
        }
    }
}
